<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    用户名 <input type="text" id="username">
    密码<input type="text" id="passwod">
    <button id="submit-btn">提交</button>
</body>

</html>
<script>
    Function.prototype.before = function (beforFn) {
        let _this = this;
        return function () {
            let ret = beforFn.apply(this, arguments)
            if (ret) // 校验成功是true，可以提交
                _this.apply(this, arguments);
        }
    }
    function sumbit() {
        console.log("提交表单")
    }
    let checkoutNamelen = sumbit.before(function () {
        let username = document.querySelector("#username").value;
        if (username.length < 6) {
            return alert("不能小于6")
        }
        return true
    })
    let checkoutName = checkoutNamelen.before(function () {
        let username = document.querySelector("#username").value;
        let password = document.querySelector("#passwod").value;
        if (!username) {
            return alert("用户名不能为空")
        } 
        return true
    })
    
    document.querySelector("#submit-btn").addEventListener("click", checkoutName)
</script>